package com.fate.system.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.fate.system.dto.wx.QrCodeDTO;
import com.fate.system.service.IWxService;
import com.fate.system.vo.wx.WxOpenIdVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@Tag(name = "微信接口操作 API")
@RestController
@RequestMapping("/api/v1.0/wx")
public class WxController {
  @Resource private IWxService wxService;

  @SaIgnore
  @Operation(summary = "获取获取小程序码")
  @GetMapping("/getQrCode")
  public void getQrCode(@Valid QrCodeDTO qrCodeDTO, HttpServletResponse response) throws Exception {
    String path = qrCodeDTO.getPath();
    String envVersion = qrCodeDTO.getEnvVersion();
    Integer width = qrCodeDTO.getWidth();
    Boolean isHyaline = qrCodeDTO.getIsHyaline();
    wxService.getQrCode(path, envVersion, width, isHyaline, response);
  }

  @SaIgnore
  @Operation(summary = "获取用户openId")
  @GetMapping("/getUserOpenId")
  public WxOpenIdVO getUserOpenId(@RequestParam String code) throws Exception {
    return wxService.getUserOpenId(code);
  }
}
